import { FC, useMemo } from 'react';
import { RouteComponentProps } from 'react-router';
import _ from 'lodash';
import { WithNormalRender } from '@/biz-components/hoc-form/with-normal';
import api from './services';
import { onFieldMount, onFormMount } from '@formily/core';

interface ArchivesMngDetailProps extends RouteComponentProps {}

const ArchivesMngDetail: FC<ArchivesMngDetailProps> = ({
    match
}) => {
  const { arcvCode } = match.params as any;
  const detailApi: any = useMemo(() => {
    return {
        remoteUrl: api.detail,
        method: 'POST',
        remoteParams: {
          arcvCode,
        },
        pageCode: 'ArchivesManage_Archive_D',
    };
  }, [arcvCode]);

  const BillFormLayout = useMemo(() => {
    return WithNormalRender({});
  }, []);

  return (
    <BillFormLayout
        anchor
        type="DETAIL"
        {...detailApi}
        formConfigs={{
          effects: () => {
            onFormMount((form) => {
              const { attachments } = form.values;

              form.setValuesIn('attachments', attachments.map((item: any) => {
                if (item.name?.split('.').length === 1) {
                  item.name += '.pdf';
                }

                return item;
              }))
            })
          }
        }}
        filedConfig={{}}
    />
  );
};

export default ArchivesMngDetail;
